#!/bin/bash
project_name=niuniu-$1

dir_tomcat=/moumou/runenv/tomcat_${project_name}
dir_source=/moumou/web/${project_name}/ROOT
dir_war=/moumou/moum_version
dir_backup=/moumou/moum_backup

# 杀进程
pid=`ps -ef | grep java | grep tomcat_${project_name} | awk '{print $2}'`
if test -z ${pid}; then
   echo "PID 不存在"
else
   echo '被杀死的PId='${pid}
   kill -9 ${pid}
fi


echo ${dir_source}
# 若不存在，则创建目录
mkdir -pv ${dir_source}
cd ${dir_source}

# 备份代码
mkdir -pv ${dir_backup}
jar -cvfM0 ${dir_backup}/${project_name}-$(date +%Y%m%d%H).war ./*

# 解压代码
rm -rf ./*
jar -xvf ${dir_war}/${project_name}-1.0-SNAPSHOT.war

# 启动程序
echo ${dir_tomcat}
cd ${dir_tomcat}
./bin/startup.sh


